import React, { Component } from 'react'
import fetchJsonp from 'fetch-jsonp'

export default class Fetch extends Component {
    // 组件加载完成，发送网络请求
    componentDidMount(){
      // 发送网络请求
      // 1. fetch  get
        fetch('http://iwenwiki.com/api/blueberrypai/getIndexBanner.php')
            .then(res =>res.json)
            .then(res =>{
                console.log(res);
            })

        // 2. fetch post
        fetch('http://iwenwiki.com/api/blueberrypai/login.php', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            body: 'user_id=iwen@qq.com&password=iwen123&verification_code=crfvw'
        }).then(res => res.json)
        // 跨域
        fetchJsonp('https://www.baidu.com/sugrec?prod=pc&from=pc_web&wd=apple',{
          jsonpCallback :'cb'
        }).then(res => res.json()).then(res => {
          console.log(res);
        })
        // fetchJsonp('http://localhost:8080/ping').then(res => res.json())
    }
  render() {
    return (
      <div>Fetch</div>
    )
  }
}
